from typing import Dict, Optional
from .base_exchange import BaseExchange
from .okx_exchange import OKXExchange
from .binance_exchange import BinanceExchange

class ExchangeFactory:
    """交易所工厂类"""
    
    SUPPORTED_EXCHANGES = {
        'okx': OKXExchange,
        'binance': BinanceExchange
    }
    
    @classmethod
    def create_exchange(cls, exchange_name: str, api_key: str, api_secret: str) -> Optional[BaseExchange]:
        """
        创建交易所实例
        
        Args:
            exchange_name: 交易所名称 (okx/binance)
            api_key: API Key
            api_secret: API Secret
            
        Returns:
            BaseExchange实例或None
        """
        exchange_class = cls.SUPPORTED_EXCHANGES.get(exchange_name.lower())
        if not exchange_class:
            print(f"Unsupported exchange: {exchange_name}")
            return None
            
        exchange = exchange_class(api_key, api_secret)
        if exchange.initialize():
            return exchange
        return None
        
    @classmethod
    def get_supported_exchanges(cls) -> Dict:
        """获取支持的交易所列表"""
        return {name: exchange.__doc__ for name, exchange in cls.SUPPORTED_EXCHANGES.items()}
